﻿using System;
using System.Runtime.InteropServices;

public class GlobalMembersGame_control: GlobalMembersGame_battle
{
	// ****************************************************************************
	// * Punch And Kick -- a simple 2D Fighting Game.
	// *
	// * Copyright (C) 2013 by
	// * Liu Chao
	// *
	// * This file is part of the Punch And Kick project, and may only be used,
	// * modified, and distributed under the terms of the GPLv2.
	// *
	// * (GPLv2 is abbreviation of GNU General Public License Version 2)
	// *
	// * By continuing to use, modify, or distribute this file you indicate that you
	// * have read the license and understand and accept it fully.
	// *
	// * The Punch And Kick project is distributed in the hope that it will be
	// * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
	// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for
	// * more details.
	// *
	// * You should have received a copy of the GPLv2 along with this file. It is
	// * usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
	// * **************************************************************************

	// ****************************************************************************
	// * Punch And Kick -- 一个普通的2D格斗游戏
	// *
	// * 版权所有 (C) 2013 归属于
	// * 刘超
	// *
	// * 这个文件是 Punch And Kick 项目的一部分，并且只可以根据GPLv2许可协议来使用、
	// * 更改和发布。
	// *
	// * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
	// *
	// * 继续使用、修改或发布本文件，表明您已经阅读并完全理解和接受这个许可协议。
	// *
	// * Punch And Kick 项目是基于技术交流目的而加以散布的，但不负任何担保责任，例
	// * 如：稳定性、可玩性、趣味性等的担保，甚至没有适销性或特定用途的隐含担保，详
	// * 情请参照GPLv2许可协议。
	// *
	// * 您应已收到附随于本文件的GPLv2许可协议的副本，它通常在LICENSE.TXT文件中，如果
	// * 没有，请查看：<http://www.gnu.org/licenses/>.
	// * **************************************************************************

	// 游戏角色控制模块，夹杂了些其它乱七八糟的代码

	//static int state_action_map[GamePlayerState.TOTAL_STATE_NUM];
	//static ActionType[] state_action_map;
	static int[] state_action_map = new int[(int)GamePlayerState.TOTAL_STATE_NUM];
	internal static void ControlKey_Init(ControlKey_ key)
	{
		key.up = 0;
		key.down = 0;
		key.left = 0;
		key.right = 0;
		key.a_attack = 0;
		key.b_attack = 0;
		key.jump = 0;
		key.defense = 0;
	}

	//* 重置攻击控制 
	public static void GamePlayer_ResetAttackControl(GamePlayer_ player)
	{
		player.control.a_attack = DefineConstantsGame_control.FALSE;
		player.control.b_attack = DefineConstantsGame_control.FALSE;
	}

	//* 重置控制数据 
	public static void GamePlayer_ResetControl(GamePlayer_ player)
	{
		player.control.down_motion = DefineConstantsGame_control.FALSE;
		player.control.up_motion = DefineConstantsGame_control.FALSE;
		player.control.left_motion = DefineConstantsGame_control.FALSE;
		player.control.right_motion = DefineConstantsGame_control.FALSE;
		player.control.a_attack = DefineConstantsGame_control.FALSE;
		player.control.b_attack = DefineConstantsGame_control.FALSE;
		player.control.run = DefineConstantsGame_control.FALSE;
		player.control.jump = DefineConstantsGame_control.FALSE;
		player.control.defense = DefineConstantsGame_control.FALSE;
	}

	//* 设置角色面向右方 
	public static void GamePlayer_SetRightOriented(GamePlayer_ player)
	{
		player.right_direction = DefineConstantsGame_control.TRUE;
		GlobalMembersGame_object.GameObject_SetHorizFlip(player.object_, DefineConstantsGame_control.FALSE);
	}

	//* 设置角色面向左方 
	public static void GamePlayer_SetLeftOriented(GamePlayer_ player)
	{
		player.right_direction = DefineConstantsGame_control.FALSE;
		GlobalMembersGame_object.GameObject_SetHorizFlip(player.object_, DefineConstantsGame_control.TRUE);
	}

	//* 判断角色是否面向左方 
	public static LCUI_BOOL GamePlayer_IsLeftOriented(GamePlayer_ player)
	{
		return !player.right_direction;
	}

	//* 改变角色的动作动画  
	public static void GamePlayer_ChangeAction(GamePlayer_ player, int action_id)
	{
        GameMsg msg = new GameMsg();
        msg.battle_id = player.battle_id;
        msg.player_id = player.id;
        msg.msg.msg_id = (int)GameMsgID.GAMEMSG_ACTION;
        msg.msg.action.action_id = action_id;
        Game_PostMsg(msg);
    }

	internal static void GamePlayer_BreakActionTiming(GamePlayer_ player)
	{
		if(player.t_action_timeout != -1)
		{
			LCUITimer_Free(player.t_action_timeout);
			player.t_action_timeout = -1;
		}
	}
    public  delegate void funcDelegate(GamePlayer_ UnnamedParameter1);
	//* 为游戏角色的动作设置时限，并在超时后进行响应 
	public static void GamePlayer_SetActionTimeOut(GamePlayer_ player, int n_ms, funcDelegate func)
	{
		int lost_ms = new int();
		lost_ms = LCUI_GetTickCount();
		GamePlayer_BreakActionTiming(player);
		//player.t_action_timeout = LCUITimer_Set(n_ms, (void(IntPtr))func, player, DefineConstantsGame_control.FALSE);
		player.t_action_timeout = LCUITimer_Set(n_ms, func, player, DefineConstantsGame_control.FALSE);
	}

   

    //* 初始化状态与动作的映射表 
    public static void Game_InitStateActionMap()
	{
		state_action_map[(int)GamePlayerState.STATE_START] = (int)ActionType.ACTION_START;
		state_action_map[(int)GamePlayerState.STATE_LYING_DYING] = (int)ActionType.ACTION_LYING_DYING;
		state_action_map[(int)GamePlayerState.STATE_TUMMY_DYING] = (int)ActionType.ACTION_TUMMY_DYING;
		state_action_map[(int)GamePlayerState.STATE_READY] = (int)ActionType.ACTION_READY;
		state_action_map[(int)GamePlayerState.STATE_STANCE] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_STANCE] = (int)ActionType.ACTION_STANCE;
		state_action_map[(int)GamePlayerState.STATE_WALK] = (int)ActionType.ACTION_WALK;
		state_action_map[(int)GamePlayerState.STATE_LEFTRUN] = state_action_map[(int)GamePlayerState.STATE_RIGHTRUN] = (int)ActionType.ACTION_RUN;
		state_action_map[(int)GamePlayerState.STATE_DEFENSE] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_DEFENSE] = (int)ActionType.ACTION_DEFENSE;
		state_action_map[(int)GamePlayerState.STATE_SOLID_DEFENSE] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_SOLID_DEFENSE] = (int)ActionType.ACTION_SOLID_DEFENSE;
		state_action_map[(int)GamePlayerState.STATE_A_ATTACK] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_A_ATTACK] = (int)ActionType.ACTION_A_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_B_ATTACK] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_B_ATTACK] = (int)ActionType.ACTION_B_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_MAJ_ATTACK] = (int)ActionType.ACTION_JUMP_MACH_A_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_MACH_A_ATTACK] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_MACH_A_ATTACK] = (int)ActionType.ACTION_MACH_A_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_MBJ_ATTACK] = (int)ActionType.ACTION_JUMP_MACH_B_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_MACH_B_ATTACK] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_MACH_B_ATTACK] = (int)ActionType.ACTION_MACH_B_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_AS_ATTACK] = (int)ActionType.ACTION_AS_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_BS_ATTACK] = (int)ActionType.ACTION_BS_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_ASJ_ATTACK] = (int)ActionType.ACTION_ASJ_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_BSJ_ATTACK] = (int)ActionType.ACTION_BSJ_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_AJ_ATTACK] = (int)ActionType.ACTION_AJ_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_BJ_ATTACK] = (int)ActionType.ACTION_BJ_ATTACK;
		state_action_map[(int)GamePlayerState.STATE_FINAL_BLOW] = (int)ActionType.ACTION_FINAL_BLOW;
		state_action_map[(int)GamePlayerState.STATE_JUMP_DONE] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_SQUAT] = state_action_map[(int)GamePlayerState.STATE_LIFT_SQUAT] = state_action_map[(int)GamePlayerState.STATE_JSQUAT] = state_action_map[(int)GamePlayerState.STATE_SSQUAT] = state_action_map[(int)GamePlayerState.STATE_SQUAT] = (int)ActionType.ACTION_SQUAT;
		state_action_map[(int)GamePlayerState.STATE_JUMP] = state_action_map[(int)GamePlayerState.STATE_SJUMP] = (int)ActionType.ACTION_JUMP;
		state_action_map[(int)GamePlayerState.STATE_FALL] = (int)ActionType.ACTION_FALL;
		state_action_map[(int)GamePlayerState.STATE_HIT] = (int)ActionType.ACTION_HIT;
		state_action_map[(int)GamePlayerState.STATE_HIT_FLY] = (int)ActionType.ACTION_HIT_FLY;
		state_action_map[(int)GamePlayerState.STATE_HIT_FLY_FALL] = (int)ActionType.ACTION_HIT_FLY_FALL;
		state_action_map[(int)GamePlayerState.STATE_LYING] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_LYING] = (int)ActionType.ACTION_LYING;
		state_action_map[(int)GamePlayerState.STATE_LYING_HIT] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_LYING_HIT] = (int)ActionType.ACTION_LYING_HIT;
		state_action_map[(int)GamePlayerState.STATE_TUMMY_HIT_FLY] = (int)ActionType.ACTION_TUMMY_HIT_FLY;
		state_action_map[(int)GamePlayerState.STATE_TUMMY] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_TUMMY] = (int)ActionType.ACTION_TUMMY;
		state_action_map[(int)GamePlayerState.STATE_TUMMY_HIT] = state_action_map[(int)GamePlayerState.STATE_BE_LIFT_TUMMY_HIT] = (int)ActionType.ACTION_TUMMY_HIT;
		state_action_map[(int)GamePlayerState.STATE_REST] = (int)ActionType.ACTION_REST;
		state_action_map[(int)GamePlayerState.STATE_ROLL_DOWN] = (int)ActionType.ACTION_ROLL_DOWN;
		state_action_map[(int)GamePlayerState.STATE_ROLL_UP] = (int)ActionType.ACTION_ROLL_UP;
		state_action_map[(int)GamePlayerState.STATE_F_ROLL] = (int)ActionType.ACTION_F_ROLL;
		state_action_map[(int)GamePlayerState.STATE_B_ROLL] = (int)ActionType.ACTION_B_ROLL;
		state_action_map[(int)GamePlayerState.STATE_GUILLOTINE] = (int)ActionType.ACTION_GUILLOTINE;
		state_action_map[(int)GamePlayerState.STATE_BIG_ELBOW] = state_action_map[(int)GamePlayerState.STATE_JUMP_ELBOW] = (int)ActionType.ACTION_JUMP_ELBOW;
		state_action_map[(int)GamePlayerState.STATE_RIDE_JUMP] = (int)ActionType.ACTION_FALL;
		state_action_map[(int)GamePlayerState.STATE_JUMP_STOMP] = (int)ActionType.ACTION_JUMP_STOMP;
		state_action_map[(int)GamePlayerState.STATE_KICK] = (int)ActionType.ACTION_KICK;
		state_action_map[(int)GamePlayerState.STATE_SPINHIT] = (int)ActionType.ACTION_SPINHIT;
		state_action_map[(int)GamePlayerState.STATE_BOMBKICK] = (int)ActionType.ACTION_BOMBKICK;
		state_action_map[(int)GamePlayerState.STATE_MACH_STOMP] = (int)ActionType.ACTION_MACH_STOMP;
		state_action_map[(int)GamePlayerState.STATE_CATCH] = (int)ActionType.ACTION_CATCH;
		state_action_map[(int)GamePlayerState.STATE_BE_CATCH] = (int)ActionType.ACTION_BE_CATCH;
		state_action_map[(int)GamePlayerState.STATE_HALF_LYING] = (int)ActionType.ACTION_HALF_LYING;
		state_action_map[(int)GamePlayerState.STATE_HALF_STANCE] = (int)ActionType.ACTION_HALF_STANCE;
		state_action_map[(int)GamePlayerState.STATE_BACK_BE_CATCH] = (int)ActionType.ACTION_BACK_BE_CATCH;
		state_action_map[(int)GamePlayerState.STATE_CATCH_SKILL_FA] = (int)ActionType.ACTION_CATCH_SKILL_FA;
		state_action_map[(int)GamePlayerState.STATE_CATCH_SKILL_BA] = (int)ActionType.ACTION_CATCH_SKILL_BA;
		state_action_map[(int)GamePlayerState.STATE_CATCH_SKILL_BB] = (int)ActionType.ACTION_CATCH_SKILL_BB;
		state_action_map[(int)GamePlayerState.STATE_CATCH_SKILL_FB] = (int)ActionType.ACTION_CATCH_SKILL_FB;
		state_action_map[(int)GamePlayerState.STATE_BE_PUSH] = (int)ActionType.ACTION_BE_PUSH;
		state_action_map[(int)GamePlayerState.STATE_WEAK_RUN] = state_action_map[(int)GamePlayerState.STATE_WEAK_RUN_ATTACK] = (int)ActionType.ACTION_WEAK_RUN;
		state_action_map[(int)GamePlayerState.STATE_LIFT_STANCE] = (int)ActionType.ACTION_LIFT_STANCE;
		state_action_map[(int)GamePlayerState.STATE_LIFT_WALK] = (int)ActionType.ACTION_LIFT_WALK;
		state_action_map[(int)GamePlayerState.STATE_LIFT_RUN] = (int)ActionType.ACTION_LIFT_RUN;
		state_action_map[(int)GamePlayerState.STATE_LIFT_JUMP] = (int)ActionType.ACTION_LIFT_JUMP;
		state_action_map[(int)GamePlayerState.STATE_LIFT_FALL] = (int)ActionType.ACTION_LIFT_FALL;
		state_action_map[(int)GamePlayerState.STATE_THROW] = (int)ActionType.ACTION_THROW;
		state_action_map[(int)GamePlayerState.STATE_RIDE] = (int)ActionType.ACTION_RIDE;
		state_action_map[(int)GamePlayerState.STATE_RIDE_ATTACK] = (int)ActionType.ACTION_RIDE_ATTACK;
	}

	//* 改变游戏角色的当前状态 
	public static void GamePlayer_ChangeState(GamePlayer_ player, int state)
	{
		if(player.lock_action)
		{
			return;
		}
		if(state < 0 || state >= (int)GamePlayerState.TOTAL_STATE_NUM)
		{
			return;
		}
		player.state = (int)state;
		;
		// 在切换动作时，撤销动作超时的响应 
		GamePlayer_BreakActionTiming(player);
		GamePlayer_ChangeAction(player, (int)state_action_map[(int)state]);
	}

	public static void GamePlayer_LockAction(GamePlayer_ player)
	{
		player.lock_action = DefineConstantsGame_control.TRUE;
	}

	public static void GamePlayer_UnlockAction(GamePlayer_ player)
	{
		player.lock_action = DefineConstantsGame_control.FALSE;
	}

	public static void GamePlayer_LockMotion(GamePlayer_ player)
	{
		player.lock_motion = DefineConstantsGame_control.TRUE;
	}

	public static void GamePlayer_UnlockMotion(GamePlayer_ player)
	{
		player.lock_motion = DefineConstantsGame_control.FALSE;
	}

	//* 打断休息 
	public static void GamePlayer_BreakRest(GamePlayer_ player)
	{
		if(player.t_rest_timeout != -1)
		{
			LCUITimer_Free(player.t_rest_timeout);
			player.t_rest_timeout = -1;
		}
	}

	//* 为游戏设置休息的时限，并在超时后进行响应 
	public static void GamePlayer_SetRestTimeOut(GamePlayer_ player, int n_ms, funcDelegate func)
	{
		GamePlayer_BreakRest(player);
		//player.t_rest_timeout = LCUITimer_Set(n_ms, (void(IntPtr))func, player, DefineConstantsGame_control.FALSE);
		player.t_rest_timeout = LCUITimer_Set(n_ms, func, player, DefineConstantsGame_control.FALSE);

		DEBUG_MSG("player %d start rest, n_ms: %d, timer: %d\n", player.id, n_ms, player.t_rest_timeout);
	}

	internal static int GamePlayer_InitAction(GamePlayer_ player, int id)
	{
		int i;
		ActionData_ action;

		player.state = (int)GamePlayerState.STATE_STANCE;

		for(i =0; i<(int)(int)ActionType.TOTAL_ACTION_NUM; ++i)
		{
			// 载入游戏角色资源 
			action = GlobalMembersGame_action.ActionRes_Load(id, i);
			// 将动作集添加至游戏对象 
			GlobalMembersGame_object.GameObject_AddAction(player.object_, action, i);
		}

		//Widget_SetBorder( player->object, Border(1,BORDER_STYLE_SOLID, RGB(0,0,0)) );
		return 0;
	}

	//* 设置游戏角色当前的攻击类型名称 
	public static void GamePlayer_SetAttackTypeName(GamePlayer_ player, string attack_type_name)
	{
		player.attack_type_name = attack_type_name;
		//player.attack_type_name = player.attack_type_name;
	}

	//* 按百分比扣除移动速度，n 取值范围为 0 ~ 100 
	public static void GamePlayer_ReduceSpeed(GamePlayer_ player, int n)
	{
		double speed;
		speed = GlobalMembersGame_object.GameObject_GetXSpeed(player.object_);
		speed = speed - (speed * n / 100.0);
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		speed = GlobalMembersGame_object.GameObject_GetYSpeed(player.object_);
		speed = speed - (speed * n / 100.0);
		GlobalMembersGame_object.GameObject_SetYSpeed(player.object_, speed);
	}

	internal static void GamePlayer_SetLeftLiftWalk(GamePlayer_ player)
	{
		double speed;
		if(player.lock_motion)
		{
			return;
		}
		speed = -DefineConstantsGame_control.XSPEED_WALK *player.property.speed / 100;
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_WALK);
	}

	internal static void GamePlayer_SetLeftWalk(GamePlayer_ player)
	{
		double speed;
		if(player.lock_motion)
		{
			return;
		}
		speed = -DefineConstantsGame_control.XSPEED_WALK *player.property.speed / 100;
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_WALK);
	}

	internal static void GamePlayer_SetRightWalk(GamePlayer_ player)
	{
		double speed;
		if(player.lock_motion)
		{
			return;
		}
		speed = DefineConstantsGame_control.XSPEED_WALK *player.property.speed / 100;
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_WALK);
	}

	internal static void GamePlayer_SetRightLiftWalk(GamePlayer_ player)
	{
		double speed;
		if(player.lock_motion)
		{
			return;
		}
		speed = DefineConstantsGame_control.XSPEED_WALK* player.property.speed / 100;
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_WALK);
	}

	internal static void GamePlayer_SetLeftRun(GamePlayer_ player)
	{
		double speed;
		if(player.lock_motion)
		{
			return;
		}
		speed = -DefineConstantsGame_control.XSPEED_RUN* player.property.speed / 100;
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LEFTRUN);
	}

	internal static void GamePlayer_SetRightRun(GamePlayer_ player)
	{
		double speed;
		if(player.lock_motion)
		{
			return;
		}
		speed = DefineConstantsGame_control.XSPEED_RUN* player.property.speed / 100;
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_RIGHTRUN);
	}

	internal static void GamePlayer_AtRunEnd(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		player = GameBattle_GetPlayerByWidget(widget);
		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockMotion(player);
	}

	internal static void GamePlayer_AtReadyTimeOut(GamePlayer_ player)
	{
		player.t_action_timeout = -1;
		if(player.state == (int)GamePlayerState.STATE_READY)
		{
			// 改为站立状态 
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_STANCE);
		}
	}

	//* 检测玩家是否处于举起状态 
	public static LCUI_BOOL GamePlayer_IsInLiftState(GamePlayer_ player)
	{
		switch((GamePlayerState)player.state)
		{
		case GamePlayerState.STATE_LIFT_SQUAT:
		case GamePlayerState.STATE_LIFT_FALL:
		case GamePlayerState.STATE_LIFT_STANCE:
		case GamePlayerState.STATE_LIFT_JUMP:
		case GamePlayerState.STATE_LIFT_RUN:
		case GamePlayerState.STATE_LIFT_WALK:
			return DefineConstantsGame_control.TRUE;
		default:
			break;
		}
		return DefineConstantsGame_control.FALSE;
	}

	public static void GamePlayer_SetReady(GamePlayer_ player)
	{
		int lost_ms = new int();
		if(player.lock_action)
		{
			return;
		}
		lost_ms = LCUI_GetTickCount();
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_READY);
		// 设置响应动作超时信号 
		GamePlayer_SetActionTimeOut(player, 1000, GamePlayer_AtReadyTimeOut);
	}

	//* 暂停游戏角色的所有活动 
	public static void GamePlayer_SetPause(GamePlayer_ player, LCUI_BOOL need_pause)
	{
		if (need_pause)
		{
			GlobalMembersGame_object.GameObject_PauseAction(player.object_);
			if(player.t_action_timeout != -1)
			{
				LCUITimer_Pause(player.t_action_timeout);
			}
			if(player.t_death_timer != -1)
			{
				LCUITimer_Pause(player.t_death_timer);
			}
			if(player.t_rest_timeout != -1)
			{
				LCUITimer_Pause(player.t_rest_timeout);
			}
		}
		else
		{
			GlobalMembersGame_object.GameObject_PlayAction(player.object_);
			if(player.t_action_timeout != -1)
			{
				LCUITimer_Continue(player.t_action_timeout);
			}
			if(player.t_death_timer != -1)
			{
				LCUITimer_Continue(player.t_death_timer);
			}
			if(player.t_rest_timeout != -1)
			{
				LCUITimer_Continue(player.t_rest_timeout);
			}
		}
	}

	//* 响应定时器，让玩家逐渐消失 
	internal static void GamePlayer_GraduallyDisappear(IntPtr arg)
	{
		byte alpha;
		GamePlayer_ player;

		//player = (GamePlayer_)arg;
		player = (GamePlayer_)Marshal.PtrToStructure(arg, typeof(GamePlayer_));
		alpha = Widget_GetAlpha(player.object_);
		if(alpha >= 5)
		{
			alpha -= 5;
			Widget_SetAlpha(player.object_, alpha);
		}
		else
		{
			Widget_SetAlpha(player.object_, 0);
			Widget_Hide(player.object_);
			player.enable = DefineConstantsGame_control.FALSE;
			player.state = (int)GamePlayerState.STATE_DIED;
			LCUITimer_Free(player.t_death_timer);
			player.t_death_timer = -1;
		}
	}

	internal static void GamePlayer_AtStandDone(LCUI_Widget_ widget)
	{
		GamePlayer_ player;

		player = GameBattle_GetPlayerByWidget(widget);
		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockMotion(player);
		GamePlayer_ResetAttackControl(player);
		GamePlayer_SetReady(player);
	}

	//* 开始站起 
	public static void GamePlayer_StartStand(GamePlayer_ player)
	{
		GamePlayer_ other_player;
		DEBUG_MSG("tip, player %d start stand\n", player.id);
		// 如果已经死了，就不站起来了 
		if(player.state == (int)GamePlayerState.STATE_DIED || player.state == (int)GamePlayerState.STATE_LYING_DYING || player.state == (int)GamePlayerState.STATE_TUMMY_DYING)
		{
			DEBUG_MSG("tip1, player->id: %d\n", player.id);
			return;
		}
		// 如果有其他玩家记录 
		if(player.other)
		{
			other_player = player.other;
			// 根据对方玩家状态， 
			switch((GamePlayerState)other_player.state)
			{
			// 如果对方正处于举起状态，那么现在就不站起了 
			case GamePlayerState.STATE_LIFT_SQUAT:
				DEBUG_MSG("tip2, player->id: %d\n", player.id);
				return;
			case GamePlayerState.STATE_RIDE_JUMP:
				break;
			case GamePlayerState.STATE_RIDE:
			case GamePlayerState.STATE_RIDE_ATTACK:
				GamePlayer_UnlockAction(player.other);
				// 解除对方的记录 
				player.other.other = null;
				player.other = null;
				// 让骑在自己身上的角色站起来 
				GamePlayer_StartStand(other_player);
				break;
			default:
				break;
			}
		}
		DEBUG_MSG("tip3, player->id: %d\n", player.id);
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_SQUAT);
		GamePlayer_LockAction(player);
		GamePlayer_LockMotion(player);
		GlobalMembersGame_object.GameObject_AtActionDone(player.object_,(int) (int)ActionType.ACTION_SQUAT, GamePlayer_AtStandDone);
	}

	//* 让玩家去死 
	internal static void GamePlayer_SetDeath(GamePlayer_ player)
	{
		GamePlayer_ other_player;
		if(player.state == (int)GamePlayerState.STATE_LYING)
		{
			GamePlayer_UnlockAction(player);
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LYING_DYING);
			GamePlayer_LockAction(player);
		}
		else if(player.state == (int)GamePlayerState.STATE_TUMMY)
		{
			GamePlayer_UnlockAction(player);
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_TUMMY_DYING);
			GamePlayer_LockAction(player);
		}
		else
		{
			return;
		}
		if(player.other)
		{
			other_player = player.other;
			switch((GamePlayerState)other_player.state)
			{
			case GamePlayerState.STATE_RIDE:
			case GamePlayerState.STATE_RIDE_ATTACK:
				GamePlayer_UnlockAction(player.other);
				// 解除对方的记录 
				player.other.other = null;
				player.other = null;
				// 让骑在自己身上的角色站起来 
				GamePlayer_StartStand(other_player);
				break;
			case GamePlayerState.STATE_RIDE_JUMP:
			default:
				break;
			}
		}
		player.t_death_timer = LCUITimer_Set(50, GamePlayer_GraduallyDisappear, player, DefineConstantsGame_control.TRUE);
	}

	public static int GamePlayer_SetLying(GamePlayer_ player)
	{
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LYING);
		GamePlayer_LockAction(player);
		// 如果没血了 
		if(player.property.cur_hp <= 0)
		{
			GamePlayer_SetDeath(player);
			return -1;
		}
		return 0;
	}

	public static int GamePlayer_SetTummy(GamePlayer_ player)
	{
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_TUMMY);
		GamePlayer_LockAction(player);
		if(player.property.cur_hp <= 0)
		{
			GamePlayer_SetDeath(player);
			return -1;
		}
		return 0;
	}

	//* 在跳跃结束时 
	internal static void GamePlayer_AtJumpDone(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		player = GameBattle_GetPlayerByWidget(widget);
		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockMotion(player);
		GamePlayer_SetReady(player);
	}

	//* 在着陆完成时 
	internal static void GamePlayer_AtLandingDone(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		player = GameBattle_GetPlayerByWidget(widget);
		GamePlayer_ResetAttackControl(player);
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_JUMP_DONE);
		GamePlayer_LockAction(player);
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, 0);
		GlobalMembersGame_object.GameObject_SetYSpeed(player.object_, 0);
		GlobalMembersGame_object.GameObject_AtActionDone(player.object_, (int)ActionType.ACTION_SQUAT, GamePlayer_AtJumpDone);
	}

	//* 被举着，站立 
	internal static void GamePlayer_SetBeLiftStance(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		player = GameBattle_GetPlayerByWidget(widget);
		if(player.state != (int)GamePlayerState.STATE_BE_LIFT_SQUAT)
		{
			return;
		}
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_BE_LIFT_STANCE);
	}

	//* 被举着，准备站起 
	internal static void GamePlayer_BeLiftStartStand(GamePlayer_ player)
	{
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_BE_LIFT_SQUAT);
		GlobalMembersGame_object.GameObject_AtActionDone(player.object_, (int)ActionType.ACTION_SQUAT, GamePlayer_SetBeLiftStance);
		GamePlayer_LockAction(player);
	}

	//* 在歇息状态结束后 
	internal static void GamePlayer_AtRestTimeOut(GamePlayer_ player)
	{
		player.n_attack = 0;
		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockMotion(player);
		GamePlayer_SetReady(player);
	}

	//* 设置为歇息状态 
	public static void GamePlayer_SetRest(GamePlayer_ player)
	{
		GamePlayer_UnlockAction(player);
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_REST);
		GamePlayer_LockAction(player);
		// 该状态最多维持两秒 
		GamePlayer_SetActionTimeOut(player, 2000, GamePlayer_AtRestTimeOut);
	}

	internal static void GamePlayer_StopLiftRun(GamePlayer_ player)
	{
		double speed;
		double acc;
		acc = 0 - GlobalMembersGame_object.GameObject_GetXSpeed(player.object_)*2.0;
		player.control.run = DefineConstantsGame_control.FALSE;
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_STANCE);
		GamePlayer_LockAction(player);
		GamePlayer_LockMotion(player);
		GlobalMembersGame_object.GameObject_AtXSpeedToZero(player.object_, acc, GamePlayer_AtRunEnd);
		speed = GlobalMembersGame_object.GameObject_GetYSpeed(player.object_);
		acc = 0 - GlobalMembersGame_object.GameObject_GetYSpeed(player.object_)*2.0;
		GlobalMembersGame_object.GameObject_SetYAcc(player.object_, acc);
	}

	//* 停止奔跑 
	public static void GamePlayer_StopRun(GamePlayer_ player)
	{
		double speed;
		double acc;
		acc = 0 - GlobalMembersGame_object.GameObject_GetXSpeed(player.object_)*3;
		player.control.run = DefineConstantsGame_control.FALSE;
		GamePlayer_SetReady(player);
		GamePlayer_LockAction(player);
		GamePlayer_LockMotion(player);
		GlobalMembersGame_object.GameObject_AtXSpeedToZero(player.object_, acc, GamePlayer_AtRunEnd);
		speed = GlobalMembersGame_object.GameObject_GetYSpeed(player.object_);
		acc = 0 - GlobalMembersGame_object.GameObject_GetYSpeed(player.object_)*2.0;
		GlobalMembersGame_object.GameObject_SetYAcc(player.object_, acc);
	}

	//* 抓住正处于喘气（歇息）状态下的玩家 
	public static GamePlayer_ GamePlayer_CatchGaspingPlayer(GamePlayer_ player)
	{
		RangeBox_ range = new RangeBox_();
		LCUI_Widget_ obj;

		// 前面一块区域 
		range.x = 11;
		range.x_width = 5;
		range.y = -DefineConstantsGame_control.GLOBAL_Y_WIDTH/2;
		range.y_width = DefineConstantsGame_control.GLOBAL_Y_WIDTH;
		range.z = 0;
		range.z_width = 64;

		obj = GlobalMembersGame_object.GameObject_GetObjectInRange(player.object_, range, DefineConstantsGame_control.TRUE, (int)ActionType.ACTION_REST);
		if(obj == null)
		{
			return null;
		}
		return GameBattle_GetPlayerByWidget(obj);
	}

	internal static void GamePlayer_SetLeftMotion(GamePlayer_ player)
	{
		int skill_id;
		double speed;

		if(player.lock_motion)
		{
			if(player.state == (int)GamePlayerState.STATE_JUMP || player.state == (int)GamePlayerState.STATE_SJUMP || player.state == (int)GamePlayerState.STATE_SQUAT || player.state == (int)GamePlayerState.STATE_LIFT_JUMP || player.state == (int)GamePlayerState.STATE_LIFT_FALL)
			{
				if(!player.lock_action)
				{
					GamePlayer_SetLeftOriented(player);
				}
			}
			else if(player.state == (int)GamePlayerState.STATE_CATCH && player.other!=null && player.other.state == (int)GamePlayerState.STATE_BACK_BE_CATCH)
			{
				GamePlayer_SetLeftOriented(player);
				GamePlayer_SetLeftOriented(player.other);
				GlobalMembersSkills_common.CommonSkill_SetPositionAtCatch(player, player.other);
			}
			else if(player.state == (int)GamePlayerState.STATE_BE_LIFT_STANCE)
			{
				GamePlayer_SetLeftOriented(player);
			}
			return;
		}
		switch((GamePlayerState)player.state)
		{
		case GamePlayerState.STATE_LIFT_WALK:
		case GamePlayerState.STATE_LIFT_STANCE:
			if(!player.lock_action)
			{
				GamePlayer_SetLeftOriented(player);
			}
			if(player.control.run)
			{
				speed = -DefineConstantsGame_control.XSPEED_RUN* player.property.speed / 10;
				GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
				GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_RUN);
			}
			else
			{
				 GamePlayer_SetLeftLiftWalk(player);
			}
			break;
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_DEFENSE:
		case GamePlayerState.STATE_WALK:
			if(!player.lock_action)
			{
				GamePlayer_SetLeftOriented(player);
			}
			skill_id = GlobalMembersGame_skill.SkillLibrary_GetSkill(player);
			if(skill_id > 0)
			{
				GlobalMembersGame_skill.GamePlayer_RunSkill(player, skill_id);
			}
			if(player.control.run)
			{
				 GamePlayer_SetLeftRun(player);
			}
			else
			{
				 GamePlayer_SetLeftWalk(player);
			}
				break;
			//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case GamePlayerState.STATE_LEFTRUN:
			break;
		case GamePlayerState.STATE_RIGHTRUN:
			GamePlayer_StopRun(player);
			break;
		case GamePlayerState.STATE_LIFT_RUN:
			if (GamePlayer_IsLeftOriented(player))
			{
				break;
			}
			GamePlayer_StopLiftRun(player);
				break;
			//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
			default:
			break;
		}
	}

	internal static void GamePlayer_SetRightMotion(GamePlayer_ player)
	{
		int skill_id;
		double speed;

		if(player.lock_motion)
		{
			if(player.state == (int)GamePlayerState.STATE_JUMP || player.state == (int)GamePlayerState.STATE_SJUMP || player.state == (int)GamePlayerState.STATE_SQUAT || player.state == (int)GamePlayerState.STATE_LIFT_JUMP || player.state == (int)GamePlayerState.STATE_LIFT_FALL)
			{
				if(!player.lock_action)
				{
					GamePlayer_SetRightOriented(player);
				}
			}
			else if(player.state == (int)GamePlayerState.STATE_CATCH && player.other!=null && player.other.state == (int)GamePlayerState.STATE_BACK_BE_CATCH)
			{
				GamePlayer_SetRightOriented(player);
				GamePlayer_SetRightOriented(player.other);
				GlobalMembersSkills_common.CommonSkill_SetPositionAtCatch(player, player.other);
			}
			else if(player.state == (int)GamePlayerState.STATE_BE_LIFT_STANCE)
			{
				GamePlayer_SetRightOriented(player);
			}
			return;
		}
		switch((GamePlayerState)player.state)
		{
		case GamePlayerState.STATE_LIFT_WALK:
		case GamePlayerState.STATE_LIFT_STANCE:
			if(!player.lock_action)
			{
				GamePlayer_SetRightOriented(player);
			}
			if(player.control.run)
			{
				speed = DefineConstantsGame_control.XSPEED_RUN *player.property.speed / 10;
				GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, speed);
				GamePlayer_ChangeState(player,(int) GamePlayerState.STATE_LIFT_RUN);
			}
			else
			{
				GamePlayer_SetRightLiftWalk(player);
			}
			break;
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_DEFENSE:
		case GamePlayerState.STATE_WALK:
			if(!player.lock_action)
			{
				GamePlayer_SetRightOriented(player);
			}
			skill_id = GlobalMembersGame_skill.SkillLibrary_GetSkill(player);
			if(skill_id > 0)
			{
				GlobalMembersGame_skill.GamePlayer_RunSkill(player, skill_id);
			}
			if(player.control.run)
			{
				 GamePlayer_SetRightRun(player);
			}
			else
			{
				 GamePlayer_SetRightWalk(player);
			}
				break;
			//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
			case GamePlayerState.STATE_RIGHTRUN:
			break;
		case GamePlayerState.STATE_LEFTRUN:
			GamePlayer_StopRun(player);
			break;
		case GamePlayerState.STATE_LIFT_RUN:
			if (GamePlayer_IsLeftOriented(player) == null)
			{
				break;
			}
			GamePlayer_StopLiftRun(player);
			break;
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
		default:
			break;
		}
	}

	public static void GamePlayer_StopXWalk(GamePlayer_ player)
	{
		if(player.lock_motion)
		{
			return;
		}
		switch((GamePlayerState)player.state)
		{
		case GamePlayerState.STATE_LEFTRUN:
		case GamePlayerState.STATE_RIGHTRUN:
		case GamePlayerState.STATE_LIFT_RUN:
		case GamePlayerState.STATE_LIFT_JUMP:
		case GamePlayerState.STATE_LIFT_FALL:
		case GamePlayerState.STATE_THROW:
			return;
		default:
			GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, 0);
			break;
		}
	}

	public static void GamePlayer_StopYMotion(GamePlayer_ player)
	{
		GlobalMembersGame_object.GameObject_SetYSpeed(player.object_, 0);
		GlobalMembersGame_object.GameObject_SetYAcc(player.object_, 0);
	}

	public static void GamePlayer_StopXMotion(GamePlayer_ player)
	{
		GlobalMembersGame_object.GameObject_SetXSpeed(player.object_, 0);
		GlobalMembersGame_object.GameObject_SetXAcc(player.object_, 0);
	}

	public static void GamePlayer_SetUpMotion(GamePlayer_ player)
	{
		double speed;
		int skill_id;

		if(player.lock_motion)
		{
			return;
		}
		switch((GamePlayerState)player.state)
		{
		case GamePlayerState.STATE_LIFT_STANCE:
		case GamePlayerState.STATE_LIFT_WALK:
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_WALK);
			break;
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_DEFENSE:
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_WALK);
			break;
		case GamePlayerState.STATE_WALK:
			skill_id = GlobalMembersGame_skill.SkillLibrary_GetSkill(player);
			if(skill_id > 0)
			{
				GlobalMembersGame_skill.GamePlayer_RunSkill(player, skill_id);
				return;
			}
				break;
		case GamePlayerState.STATE_LEFTRUN:
		case GamePlayerState.STATE_RIGHTRUN:
		case GamePlayerState.STATE_LIFT_RUN:
			break;
		default:
			return;
		}
		speed = -DefineConstantsGame_control.YSPEED_WALK* player.property.speed / 10;
		GlobalMembersGame_object.GameObject_SetYSpeed(player.object_, speed);
	}

	//* 设置向上移动 
	public static void GamePlayer_SetDownMotion(GamePlayer_ player)
	{
		double speed;
		int skill_id;

		if(player.lock_motion)
		{
			return;
		}
		switch((GamePlayerState)player.state)
		{
		case GamePlayerState.STATE_LIFT_STANCE:
		case GamePlayerState.STATE_LIFT_WALK:
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_WALK);
			break;
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_DEFENSE:
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_WALK);
				break;
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
		case GamePlayerState.STATE_WALK:
			skill_id = GlobalMembersGame_skill.SkillLibrary_GetSkill(player);
			if(skill_id > 0)
			{
				GlobalMembersGame_skill.GamePlayer_RunSkill(player, skill_id);
				return;
			}
				break;
		case GamePlayerState.STATE_LEFTRUN:
		case GamePlayerState.STATE_RIGHTRUN:
		case GamePlayerState.STATE_LIFT_RUN:
			break;
		default:
			return;
		}
		speed = DefineConstantsGame_control.YSPEED_WALK * player.property.speed / 10;
		GlobalMembersGame_object.GameObject_SetYSpeed(player.object_, speed);
	}

	//* 响应游戏角色受到的攻击 
	internal static void GamePlayer_ResponseAttack(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		GamePlayer_ atk_player;
		AttackerInfo_ p_info;
		LCUI_Queue attacker_info;

		player = GameBattle_GetPlayerByWidget(widget);
		if(player == null)
		{
			return;
		}

		attacker_info = GlobalMembersGame_object.GameObject_GetAttackerInfo(widget);
		while(true)
		{
			p_info = (AttackerInfo_)Queue_Get(attacker_info, 0);
			if(p_info == null)
			{
				break;
			}
			atk_player = GameBattle_GetPlayerByWidget(p_info.attacker);
			// 记录本次攻击的信息 
			//Game_RecordAttack(atk_player, atk_player.attack_type_name, player, player.state);
			// 删除攻击者记录 
			Queue_Delete(attacker_info, 0);
		}
	}

	//* 初始化游戏玩家数据 
	public static void GamePlayer_Init(GamePlayer_ player)
	{
		player.id = 0;
		player.role_id = 0;
		player.type = 0;
		player.state = 0;
		player.enable = DefineConstantsGame_control.FALSE;
		player.right_direction = DefineConstantsGame_control.TRUE;
		player.human_control = DefineConstantsGame_control.TRUE;
		player.local_control = DefineConstantsGame_control.TRUE;
		player.lock_action = DefineConstantsGame_control.FALSE;
		player.lock_motion = DefineConstantsGame_control.FALSE;
		player.is_invincible = DefineConstantsGame_control.FALSE;
		player.property.cur_hp = 0;
		player.property.max_hp = 0;
		player.property.defense = 0;
		player.property.kick = 0;
		player.property.punch = 0;
		player.property.speed = 100;
		player.property.throw_ = 0;

		GlobalMembersGame_skill.GamePlayer_InitSkillRecord(player);

		player.n_attack = 0;
		player.t_rest_timeout = -1;
		player.t_action_timeout = -1;
		player.t_death_timer = -1;
		player.object_ = null;
		player.statusbar = null;
		player.other = null;
		player.control.a_attack = DefineConstantsGame_control.FALSE;
		player.control.b_attack = DefineConstantsGame_control.FALSE;
		player.control.run = DefineConstantsGame_control.FALSE;
		player.control.left_motion = DefineConstantsGame_control.FALSE;
		player.control.right_motion = DefineConstantsGame_control.FALSE;
		player.control.up_motion = DefineConstantsGame_control.FALSE;
		player.control.down_motion = DefineConstantsGame_control.FALSE;
		player.control.jump = DefineConstantsGame_control.FALSE;
		player.control.defense = DefineConstantsGame_control.FALSE;
		player.ai_data.strategy_id = 0;
		player.ai_data.target_update_time = 0;
		player.ai_data.action_num = 0;

		ControlKey_Init(player.ctrlkey);
		player.object_ = null;
	}

	//* 响应按键的按下 
	internal static void GameKeyboardProcKeyDown(int key_code)
	{
		GamePlayer_ target;

		target = GlobalMembersGame_battle.GameBattle_GetPlayerByControlKey(key_code);
		if(target == null)
		{
			return;
		}
		if(key_code == target.ctrlkey.left)
		{
			if (LCUIKey_IsDoubleHit(target.ctrlkey.left, 100,target .right_direction))
			{
				target.control.run = DefineConstantsGame_control.TRUE;
			}
		}
		else if(key_code == target.ctrlkey.right)
		{
			if (LCUIKey_IsDoubleHit(target.ctrlkey.right, 100, target.right_direction))
			{
				target.control.run = DefineConstantsGame_control.TRUE;
			}
		}
		if (key_code == target.ctrlkey.jump||GetAKey()&& GetBKey())
		{
			target.control.jump = DefineConstantsGame_control.TRUE;
		}
		else if (key_code == target.ctrlkey.a_attack)
		{
			target.control.a_attack = DefineConstantsGame_control.TRUE;
		}
		else if(key_code == target.ctrlkey.b_attack)
		{
			target.control.b_attack = DefineConstantsGame_control.TRUE;
		}
	}

	//* 处理键盘事件 
	public static void GameControl_KeyboardProc(LCUI_Event event_, IntPtr arg)
	{
		if (event_.type ==0)// (int)AnonymousEnum.LCUI_KEYDOWN)
		{
			GameKeyboardProcKeyDown(event_.key.key_code);
		}
	}

//* 同步游戏玩家的按键控制 
    public static void GamePlayer_SyncKeyControl(GamePlayer_ player)
	{
		player.control.left_motion = LCUIKey_IsHit(player.ctrlkey.left);
		player.control.right_motion = LCUIKey_IsHit(player.ctrlkey.right);
		player.control.up_motion = LCUIKey_IsHit(player.ctrlkey.up);
		player.control.down_motion = LCUIKey_IsHit(player.ctrlkey.down);
		player.control.defense = LCUIKey_IsHit(player.ctrlkey.defense);
	}

    //* 同步游戏玩家的数据 
    public static void GamePlayer_SyncData(GamePlayer_ player)
	{
		int skill_id;
		LCUI_BOOL stop_xmotion =DefineConstantsGame_control.FALSE;
		LCUI_BOOL stop_ymotion =DefineConstantsGame_control.FALSE;

		if(player.control.left_motion)
		{
			GamePlayer_SetLeftMotion(player);
		}
		else if(player.control.right_motion)
		{
			GamePlayer_SetRightMotion(player);
		}
		else
		{
			GamePlayer_StopXWalk(player);
			stop_xmotion = DefineConstantsGame_control.TRUE;
		}
		if(player.control.up_motion)
		{
			GamePlayer_SetUpMotion(player);
		}
		else if(player.control.down_motion)
		{
			GamePlayer_SetDownMotion(player);
		}
		else
		{
			switch((GamePlayerState)player.state)
			{
			case GamePlayerState.STATE_LEFTRUN:
			case GamePlayerState.STATE_RIGHTRUN:
			case GamePlayerState.STATE_WALK:
			case GamePlayerState.STATE_READY:
			case GamePlayerState.STATE_STANCE:
			case GamePlayerState.STATE_LIFT_RUN:
			case GamePlayerState.STATE_LIFT_WALK:
					{
						GamePlayer_StopYMotion(player);
						stop_ymotion = DefineConstantsGame_control.TRUE;
						break;
					}
//C++ TO C# CONVERTER TODO TASK: C# does not allow fall-through from a non-empty 'case':
			default:
				break;
			}
		}
		if(stop_xmotion  && stop_ymotion )
		{
			if(player.state == (int)GamePlayerState.STATE_WALK)
			{
				GamePlayer_ChangeState(player,(int) GamePlayerState.STATE_STANCE);
			}
			else if(player.state == (int)GamePlayerState.STATE_LIFT_WALK)
			{
				GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_LIFT_STANCE);
			}
		}
		if(!player.control.a_attack && !player.control.b_attack && !player.control.jump && !player.control.left_motion && !player.control.right_motion && !player.control.up_motion && !player.control.down_motion && !player.control.defense && player.state != (int)GamePlayerState.STATE_DEFENSE && player.state != (int)GamePlayerState.STATE_SOLID_DEFENSE && player.state != (int)GamePlayerState.STATE_BE_LIFT_DEFENSE && player.state != (int)GamePlayerState.STATE_BE_LIFT_SOLID_DEFENSE)
		{
			return;
		}
		skill_id = GlobalMembersGame_skill.SkillLibrary_GetSkill(player);
		if(skill_id > 0)
		{
			GlobalMembersGame_skill.GamePlayer_RunSkill(player, skill_id);
			player.control.a_attack = DefineConstantsGame_control.FALSE;
			player.control.b_attack = DefineConstantsGame_control.FALSE;
			return;
		}
		player.control.a_attack = DefineConstantsGame_control.FALSE;
		player.control.b_attack = DefineConstantsGame_control.FALSE;
		if(player.state != (int)GamePlayerState.STATE_DEFENSE && player.state != (int)GamePlayerState.STATE_SOLID_DEFENSE && player.state != (int)GamePlayerState.STATE_BE_LIFT_DEFENSE && player.state != (int)GamePlayerState.STATE_BE_LIFT_SOLID_DEFENSE)
		{
			return;
		}
		if(player.lock_action || player.control.defense)
		{
			return;
		}
		GamePlayer_UnlockMotion(player);
		// 如果处于被举起的状态，则改变状态为STATE_BE_LIFT_STANCE 
		if(player.other!=null && GamePlayer_IsInLiftState(player.other))
		{
			GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_BE_LIFT_STANCE);
			return;
		}
		if(player.state == (int)GamePlayerState.STATE_DEFENSE || player.state == (int)GamePlayerState.STATE_SOLID_DEFENSE)
		{
			GamePlayer_SetReady(player);
		}
		else if(player.state == (int)GamePlayerState.STATE_BE_LIFT_SOLID_DEFENSE && player.state == (int)GamePlayerState.STATE_BE_LIFT_DEFENSE)
		{
			 GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_BE_LIFT_STANCE);
		}
	}

	internal static void GamePlayer_SetToReady(LCUI_Widget_ widget)
	{
		GamePlayer_ player;
		player = GameBattle_GetPlayerByWidget(widget);
		GamePlayer_UnlockAction(player);
		GamePlayer_UnlockMotion(player);
		GamePlayer_SetReady(player);
	}

	//* 设置游戏角色为开打动作 
	public static void GamePlayer_SetStart(GamePlayer_ player)
	{
		GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_START);
		GlobalMembersGame_object.GameObject_AtActionDone(player.object_, (int)ActionType.ACTION_START, GamePlayer_SetToReady);
	}

	internal static RoleInfo_[] role_library = { 
		new RoleInfo_ ( RoleID.ROLE_KUNIO, "国夫", GamePlayerType.PLAYER_TYPE_FIGHTER,new GamePlayerProperty_(  1800, 1800, 60, 200, 150, 100, 100),new string [] { DefineConstantsGame_control.SKILLNAME_MACH_B_ATTACK, DefineConstantsGame_control.SKILLNAME_SPINHIT, DefineConstantsGame_control.SKILLNAME_BOMBKICK}, 3 ),
		new RoleInfo_ ( RoleID.ROLE_RIKI, "阿力", GamePlayerType.PLAYER_TYPE_MARTIAL_ARTIST, new GamePlayerProperty_( 1900, 1900, 240, 60, 100, 100, 130),new string [] { DefineConstantsGame_control.SKILLNAME_MACH_A_ATTACK, DefineConstantsGame_control.SKILLNAME_SPINHIT, DefineConstantsGame_control.SKILLNAME_TORNADO_ATTACK}, 3 ), 
		new RoleInfo_(RoleID.ROLE_MIKE, "姬山", GamePlayerType.PLAYER_TYPE_KUNG_FU, new GamePlayerProperty_(1800, 1800, 60, 240, 150, 110, 130), new string[]{ DefineConstantsGame_control.SKILLNAME_MACH_B_ATTACK, DefineConstantsGame_control.SKILLNAME_BOMBKICK, DefineConstantsGame_control.SKILLNAME_JUMP_SPINKICK }, 3 ), 
		new RoleInfo_(RoleID.ROLE_BEN, "御堂", GamePlayerType.PLAYER_TYPE_JUDO_MASTER, new GamePlayerProperty_(2200, 2200, 150, 150, 100, 150, 200), new string[] { DefineConstantsGame_control.SKILLNAME_SOLID_DEFENSE, DefineConstantsGame_control.SKILLNAME_BOMBKICK, DefineConstantsGame_control.SKILLNAME_SPINHIT}, 3 ),
		new RoleInfo_(RoleID.ROLE_TORAJI, "寅", GamePlayerType.PLAYER_TYPE_TIGER, new GamePlayerProperty_(2000, 2000, 180, 180, 150, 150, 150), new string[] { DefineConstantsGame_control.SKILLNAME_MACH_A_ATTACK, DefineConstantsGame_control.SKILLNAME_MACH_B_ATTACK, DefineConstantsGame_control.SKILLNAME_MACH_STOMP, DefineConstantsGame_control.SKILLNAME_BOMBKICK, DefineConstantsGame_control.SKILLNAME_SPINHIT, DefineConstantsGame_control.SKILLNAME_SOLID_DEFENSE, DefineConstantsGame_control.SKILLNAME_JUMP_SPINKICK, DefineConstantsGame_control.SKILLNAME_TORNADO_ATTACK, DefineConstantsGame_control.SKILLNAME_BIG_ELBOW, DefineConstantsGame_control.SKILLNAME_GUILLOTINE }, 10 ) };

	//* 获取角色信息 
	public static RoleInfo_ Game_GetRoleInfo(int role_id)
	{
		int i;
		for(i =0; i<(int)RoleID.TOTAL_ROLE_NUM; ++i)
		{
			if(role_library[i].role_id == role_id)
			{
				return role_library[i];
			}
		}

		return default (RoleInfo_);
	}
}

public struct ControlKey_
{
	public int up, down, left, right, a_attack, b_attack, defense, jump;
}

public struct GamePlayerProperty_
{
	public int max_hp; /**< 最大生命值 */
	public int cur_hp; /**< 当前生命值 */
	public int punch;  /**< 拳击的伤害 */
	public int kick;   /**< 踢的伤害 */
	public int speed;  /**< 移动速度 */
	public int throw_;  /**< 投掷伤害 */
	public int defense;

    public GamePlayerProperty_(int v1, int v2, int v3, int v4, int v5, int v6, int v7) : this()
    {
		max_hp = v1;
		cur_hp = v2;
		punch = v3;
		kick = v4;
		speed = v5;
		throw_ = v6;
		defense = v7;
	}
    /**< 防御力 */
}


public struct ControlState_
{
    public LCUI_BOOL run;          /**< 是否奔跑 */
    public LCUI_BOOL left_motion;      /**< 是否向左移动 */
    public LCUI_BOOL right_motion;     /**< 是否向右移动 */
    public LCUI_BOOL up_motion;        /**< 是否向上移动 */
    public LCUI_BOOL down_motion;      /**< 是否向下移动 */
    public LCUI_BOOL a_attack;     /**< 是否进行A攻击 */
    public LCUI_BOOL b_attack;     /**< 是否进行B攻击 */
    public LCUI_BOOL jump;         /**< 是否进行跳跃 */
    public LCUI_BOOL defense;      /**< 是否进行防御 */

 //   public bool run;          /**< 是否奔跑 */
	//public bool left_motion;      /**< 是否向左移动 */
	//public bool right_motion;     /**< 是否向右移动 */
	//public bool up_motion;        /**< 是否向上移动 */
	//public bool down_motion;      /**< 是否向下移动 */
	//public bool a_attack;     /**< 是否进行A攻击 */
	//public bool b_attack;     /**< 是否进行B攻击 */
	//public bool jump;         /**< 是否进行跳跃 */
	//public bool defense;      /**< 是否进行防御 */
}


//#define MAX_SKILL_NUM 10

public class RoleInfo_
{
	public int role_id;                /**< 角色ID */
	//wchar_t name[12];           /**< 角色名 */
	public string name;
	public int type;               /**< 角色类型 */
	public GamePlayerProperty_ property;        /**< 角色的各项属性 */
	//public char skills[DefineConstantsGame_control.MAX_SKILL_NUM][256];	/**< 拥有的技能 */
	public string[] skills;	/**< 拥有的技能 */
	public int total_skill;            /**< 技能总数 */

	public RoleInfo_(RoleID id,string name_, GamePlayerType type_, GamePlayerProperty_ property_,string[] skills_,int total)
    {
		role_id =(int) id;
		name = name_;
		type =(int)type_;
		property = property_;
		skills = skills_;
		total_skill = total;
	}
}


//public struct GamePlayer_ GamePlayer;
public class GamePlayer_
{
	public int t = 0;
	public int state { get { return t; } set { 
			t = value;
			if(value ==71)
            {

            }
		} }          /**< 状态 */
	public int battle_id;          /**< 所属对战ID */
	public int id;             /**< 玩家ID */
	public int role_id;            /**< 角色ID */
	public int type;           /**< 角色类型 */
	public GamePlayerProperty_ property;    /**< 游戏角色属性 */
	public LCUI_Queue skills=new LCUI_Queue ();      /**< 已经启用的技能 */
	public LCUI_BOOL enable;       /**< 是否启用该角色 */
	public LCUI_BOOL right_direction;  /**< 角色是否朝着右方 */
	public LCUI_BOOL human_control;    /**< 是否由人类控制 */
	public LCUI_BOOL local_control;    /**< 是否由此处玩家控制 */
	public LCUI_BOOL lock_action;      /**< 是否锁定动作 */
	public LCUI_BOOL lock_motion;      /**< 是否锁定移动 */
	public LCUI_BOOL is_invincible;    /**< 是否无敌 */
	//char attack_type_name[64];  /**< 当前的攻击类型 */
	public string attack_type_name;  /**< 当前的攻击类型 */
	public int n_attack;           /**< 被攻击的次数 */
	public int t_rest_timeout;     /**< 定时器，用于限定休息时间 */
	public int t_action_timeout;       /**< 定时器，用于处理动作超时 */
	public int t_death_timer;      /**< 死亡定时器 */
	public LCUI_Widget_ object_=new LCUI_Widget_();     /**< 游戏对象 */
	public LCUI_Widget_ statusbar;     /**< 状态栏 */
	public ControlKey_ ctrlkey;     /**< 该角色的控制键 */
	public GamePlayer_ other;
	public GameAI_Data_ ai_data;        /**< 记录AI的数据 */
	public ControlState_ control;       /**< 角色的控制状态 */

	public static implicit operator bool(GamePlayer_ mc)//隐式声明的class转bool类处理方法
	{
		return mc != null;
	}
}

public enum GamePlayerType
{
	PLAYER_TYPE_FIGHTER,
	PLAYER_TYPE_MARTIAL_ARTIST,
	PLAYER_TYPE_KUNG_FU,
	PLAYER_TYPE_JUDO_MASTER,
	PLAYER_TYPE_TIGER
};

public enum GamePlayerState
{
	STATE_START = 0,
	STATE_DIED,     /**< 已经死亡 1*/
	STATE_LYING_DYING,  /**< 躺着，快死了 2*/
	STATE_TUMMY_DYING,  /**< 趴着，快死了 */
	STATE_READY,
	STATE_STANCE,       /**< 站立 */
	STATE_WALK,     /**< 步行 */
	STATE_LEFTRUN,      /**< 向左奔跑 */
	STATE_RIGHTRUN,     /**< 向右奔跑 */
	STATE_A_ATTACK,
	STATE_B_ATTACK,
	STATE_DEFENSE,
	STATE_SOLID_DEFENSE,
	STATE_MACH_A_ATTACK,
	STATE_MACH_B_ATTACK,
	STATE_AS_ATTACK,
	STATE_BS_ATTACK,
	STATE_AJ_ATTACK,
	STATE_BJ_ATTACK,
	STATE_MAJ_ATTACK,
	STATE_MBJ_ATTACK,
	STATE_ASJ_ATTACK,
	STATE_BSJ_ATTACK,
	STATE_FINAL_BLOW,
	STATE_SQUAT,
	STATE_JSQUAT,
	STATE_SSQUAT,
	STATE_JUMP,
	STATE_SJUMP,
	STATE_JUMP_DONE,
	STATE_FALL,
	STATE_HIT,      /**< 被命中 */
	STATE_HIT_FLY,      /**< 被击飞 */
	STATE_HIT_FLY_FALL, /**< 被击飞（头朝地） */
	STATE_LYING,
	STATE_LYING_HIT,
	STATE_TUMMY_HIT_FLY,
	STATE_TUMMY,
	STATE_TUMMY_HIT,
	STATE_REST,     /**< 歇息 */
	STATE_F_ROLL,       /**< 向前翻滚 */
	STATE_B_ROLL,       /**< 向后翻滚 */
	STATE_ROLL_UP,
	STATE_ROLL_DOWN,
	STATE_ELBOW,
	STATE_JUMP_ELBOW,
	STATE_JUMP_STOMP,
	STATE_KICK,
	STATE_GUILLOTINE,
	STATE_BIG_ELBOW,
	STATE_SPINHIT,
	STATE_BOMBKICK,
	STATE_MACH_STOMP,
	STATE_CATCH,
	STATE_BE_CATCH,
	STATE_BE_PUSH,
	STATE_HALF_LYING,
	STATE_HALF_STANCE,
	STATE_BACK_BE_CATCH,
	STATE_CATCH_SKILL_FA,
	STATE_CATCH_SKILL_FB,
	STATE_CATCH_SKILL_BA,
	STATE_CATCH_SKILL_BB,
	STATE_WEAK_RUN,
	STATE_WEAK_RUN_ATTACK,
	STATE_LIFT_STANCE,      /**< 举着，站立 */
	STATE_LIFT_WALK,        /**< 举着，行走 */
	STATE_LIFT_RUN,         /**< 举着，奔跑 */
	STATE_LIFT_JUMP,        /**< 举着，跳起 */
	STATE_LIFT_FALL,        /**< 举着，下落 */
	STATE_LIFT_SQUAT,
	STATE_BE_LIFT_STANCE,       /**< 被举起，站立 */
	STATE_BE_LIFT_SQUAT,        /**< 被举起，蹲着 */
	STATE_BE_LIFT_LYING,        /**< 被举起，躺着 */
	STATE_BE_LIFT_TUMMY,        /**< 被举起，趴着 */
	STATE_BE_LIFT_LYING_HIT,    /**< 被举起，躺着挨打 */
	STATE_BE_LIFT_TUMMY_HIT,    /**< 被举起，趴着挨打 */
	STATE_BE_LIFT_A_ATTACK,
	STATE_BE_LIFT_B_ATTACK,
	STATE_BE_LIFT_MACH_A_ATTACK,
	STATE_BE_LIFT_MACH_B_ATTACK,
	STATE_BE_LIFT_DEFENSE,
	STATE_BE_LIFT_SOLID_DEFENSE,
	STATE_THROW,
	STATE_RIDE,
	STATE_RIDE_ATTACK,
	STATE_RIDE_JUMP,
	TOTAL_STATE_NUM         /**< 状态的总数量 */
};

public enum AnonymousEnum
{
	LCUI_KEYDOWN,
	LCUI_KEYUP,
	LCUI_MOUSEMOTION,
	LCUI_MOUSEBUTTONDOWN,
	LCUI_MOUSEBUTTONUP,
	LCUI_QUIT,
	LCUI_USEREVENT
}